package me.zhengjie.service.impl;

import lombok.RequiredArgsConstructor;
import me.zhengjie.WcsReport.BuzzerService;
import me.zhengjie.WcsReport.WcsReportService;
import me.zhengjie.agvSend.AgvSendService;
import me.zhengjie.pojo.dto.*;
import me.zhengjie.pojo.entity.*;
import me.zhengjie.pojo.vo.AgvTaskSubmitVo;
import me.zhengjie.service.AgvReturnService;
import me.zhengjie.sqlservice.*;
import me.zhengjie.tcp.*;
import me.zhengjie.utility.liftState.LiftTaskStatus;
import me.zhengjie.utility.state.MaterialStatus;
import me.zhengjie.utility.state.TaskStatus;
import me.zhengjie.utility.state.TaskType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.support.TransactionTemplate;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

@Service
@RequiredArgsConstructor
public class AgvReturnServiceImpl implements AgvReturnService {
    private static final Logger haikang = LoggerFactory.getLogger("haiKang");
    private static final Logger liftLog = LoggerFactory.getLogger("lift");

    private final WcsInboundMissionService wcsInboundMissionService;

    private final ChainLineTCP chainLineTCP;

    private final WcsChainLineConfigService wcsChainLineConfigService;

    private final WcsReportService wcsReportService;

    private final WcsOutboundMissionService wcsOutboundMissionService;

    private final WcsInboundMissionHistoryService wcsInboundMissionHistoryService;

    private final WcsOutboundMissionHistoryService wcsOutboundMissionHistoryService;

    private final IwsStoreOutsideService iwsSOutsideService;

    private final WcsDeliveryMissionService wcsDeliveryMissionService;

    private final WcsDeliveryMissionHistoryService wcsDeliveryMissionHistoryService;

    private final WcsInboundAbnormalMissionService wcsInboundAbnormalMissionService;

    private final WcsInboundAbnormalMissionHistoryService wcsInboundAbnormalMissionHistoryService;

    private final WcsFluentFrameConfigService wcsFluentFrameConfigService;

    private final LiftWaitPointService liftWaitPointService;

    private final LiftSqlService liftSqlService;

    private final LiftTaskService liftTaskService;

    //    private final FluentFrameTCPA fluentFrameTCPA;
//
//    private final FluentFrameTCPB fluentFrameTCPB;
    private final FluentFrame fluentFrame;

    private final WcsLineEdgeWarehouseService wcsLineEdgeWarehouseService;

//    private final InboundLineBody inboundLineBody;

    private final WcsLineBodyInboundService wcsLineBodyService;

    private final WcsLineBodyWaitOutboundService wcsLineBodyWaitOutboundService;

//    private final OutboundLineBody outboundLineBody;

    private final WcsLineBodyOutboundService wcsLineBodyOutboundService;

    private final WcsThreeFloorOutboundService wcsThreeFloorOutboundService;

    private final WcsThreeFloorOutboundHistoryService wcsThreeFloorOutboundHistoryService;

    private final WcsThreeFloorOutboundDetailsService wcsThreeFloorOutboundDetailsService;

    private final WcsThreeFloorOutboundDetailsHistoryService wcsThreeFloorOutboundDetailsHistoryService;

    private final BuzzerService buzzerService;

    private final WcsFluentFrameOutboundDetailsService wcsFluentFrameOutboundDetailsService;

    private final WcsLineBodyInboundService wcsLineBodyInboundService;

    private final WcsAgvReleaseGoodsService wcsAgvReleaseGoodsService;

    private final AgvSendService agvSendService;

    private final WcsConfigurationService wcsConfigurationService;
    private final TransactionTemplate transactionTemplate;

    private final WcsRetryPlcService wcsRetryPlcService;


    @Transactional
    @Override
    public AgvTaskSubmitVo
    agvTaskReport(AgvReturnDto agvReturnDto) {
        String robotTaskCode = agvReturnDto.getRobotTaskCode();
        String agvId = agvReturnDto.getSingleRobotCode();
        haikang.info("海康上报取放货接口：{}", agvReturnDto);
        //根据任务号判断入库任务还是出库任务
        WcsInboundMission wcsInboundMission = wcsInboundMissionService.selectInboundCode(robotTaskCode);
        WcsOutboundMission wcsOutboundMission = wcsOutboundMissionService.selectOutboundCode(robotTaskCode);
        WcsDeliveryMission wcsDeliveryMission = wcsDeliveryMissionService.selectDeliveryCode(robotTaskCode);
        WcsInboundAbnormalMission wcsInboundAbnormalMission = wcsInboundAbnormalMissionService.selectInboundAbnormalCode(robotTaskCode);
        haikang.info("agv任务上报查询结果入库;{},出库：{},配送：{},入库异常：{},", wcsInboundMission, wcsOutboundMission, wcsDeliveryMission, wcsInboundAbnormalMission);
        if (wcsInboundMission != null) {
            Integer id = wcsInboundMission.getId();
            String containerCode = wcsInboundMission.getContainerCode();
            String destination = wcsInboundMission.getDestination();
            String source = wcsInboundMission.getSource();
            String taskType = wcsInboundMission.getTaskType();
            Integer inboundType = wcsInboundMission.getInboundType();
            Integer isNest = wcsInboundMission.getIsNest();
            Integer containerType = wcsInboundMission.getContainerType();
            Integer isPlc = wcsInboundMission.getIsPlc();
            String wmsTaskId = wcsInboundMission.getWmsTaskId();
            String inboundCode = wcsInboundMission.getInboundCode();
            String floor = wcsInboundMission.getFloor();
            Integer isWms = wcsInboundMission.getIsWms();
            Integer missionStatus = wcsInboundMission.getMissionStatus();
            Extra extra = agvReturnDto.getExtra();
            Values values = extra.getValues();
            String method = values.getMethod();
            if ("start".equals(method)) {
                return AgvTaskSubmitVo.OK(robotTaskCode);
            } else if ("outbin".equals(method)) {
                if (missionStatus == 4) {
                    return AgvTaskSubmitVo.ng(robotTaskCode);
                }
                //判断入库任务是否是否是栈板入库，是就要发送给PLC容器被AGV取走
                if (isPlc == 1) {
                    if (containerType == 1) {
                        //1楼入库，需要给PLC发送容器取走
                        WcsChainLineConfig wcsChainLineConfig = wcsChainLineConfigService.selectTransportStorage(wcsInboundMission.getSource());
                        if (wcsChainLineConfig != null) {
                            Integer threeReturnResult = wcsChainLineConfig.getThreeReturnResult();
                            Integer unitId = wcsChainLineConfig.getUnitId();
                            boolean b = chainLineTCP.writeWithRetry(threeReturnResult, MaterialStatus.AGV_MOVED.getStatus(), unitId, MaterialStatus.RETRY_COUNT.getStatus());
                            if (!b) {
                                haikang.info("1F链条线入库写入失败");
                                return AgvTaskSubmitVo.ng(taskType);
                            }
                        }
                    } else if (containerType == 2 || containerType == 6) {
                        WcsFluentFrameConfig wcsFluentFrameConfig = wcsFluentFrameConfigService.selectInboundStorageCode(source);
                        haikang.info("根据起点查询流利架数据：{}", wcsFluentFrameConfig);
                        if (wcsFluentFrameConfig != null) {
                            Integer wcsFluentFrameConfigId = wcsFluentFrameConfig.getId();
                            String region = wcsFluentFrameConfig.getRegion();
                            Integer threeInbReturnResult = wcsFluentFrameConfig.getThreeInbReturnResult();
                            Integer unitId = wcsFluentFrameConfig.getUnitId();
                            haikang.info("2F入库PLC写入地址位：{}", threeInbReturnResult);
                            boolean b1 = fluentFrame.writeWithRetry(threeInbReturnResult, MaterialStatus.AGV_TRANSPORT_COMPLETE.getStatus(), unitId, MaterialStatus.RETRY_COUNT.getStatus(), region);
                            if (!b1){
                                haikang.info("2F入库PLC写入失败");
                                //写入失败，记录
                                WcsRetryPlc wcsRetryPlc = new WcsRetryPlc();
                                wcsRetryPlc.setFloor(floor);
                                wcsRetryPlc.setType(1);
                                wcsRetryPlc.setAddress(threeInbReturnResult);
                                wcsRetryPlc.setRegion(region);
                                wcsRetryPlc.setValue(MaterialStatus.AGV_TRANSPORT_COMPLETE.getStatus());
                                haikang.info("2F入库PLC写入失败,记录：{}",wcsRetryPlc);
                                wcsRetryPlcService.insert(wcsRetryPlc);
//                                return AgvTaskSubmitVo.ng(taskType);
                            }
                            //下发预调度
                            TaskPretaskDto taskPretaskDto = new TaskPretaskDto();
                            taskPretaskDto.setSiteCode(source);
                            WcsConfiguration wcsConfiguration = wcsConfigurationService.selectKey(TaskType.TWO_FLOOR_PRE_SCHEDULING_TIME.getMessage());
                            String configValue = wcsConfiguration.getConfigValue();
                            taskPretaskDto.setNextTaskTime(configValue);
                            taskPretaskDto.setRobotType("19");
                            AgvTaskSubmitVo agvTaskSubmitVo = agvSendService.taskPretask(taskPretaskDto);
                            //修改CTU取货时间
                            boolean b3 = wcsFluentFrameConfigService.updateCtuTakeTime(wcsFluentFrameConfigId);
                            //修改入库PLC状态
                            boolean b2 = wcsFluentFrameConfigService.updateInbPlcStatus(wcsFluentFrameConfig.getId(), 0);
                        }

                    }
//                    else if (containerType == 3) {
//                        WcsLineBodyInbound wcsLineBody = wcsLineBodyService.selectInbCtuStorage(source);
//                        WcsLineEdgeWarehouse wcsLineEdgeWarehouse = wcsLineEdgeWarehouseService.selectStorageCode(source);
//                        if (wcsLineBody != null) {
//                            Integer inbFeedback = wcsLineBody.getInbFeedback();
//                            Integer unitId = wcsLineBody.getUnitId();
//                            Integer readHoldingRegisters = inboundLineBody.readHoldingRegisters(inbFeedback, unitId);
//                            if (readHoldingRegisters != 1) {
//                                //重新写入1
//                                boolean b = inboundLineBody.writeWithRetry(inbFeedback, MaterialStatus.AGV_TRANSPORT_IN_THE_TASK.getStatus(), unitId, MaterialStatus.RETRY_COUNT.getStatus());
//                                if (!b){
//                                    return AgvTaskSubmitVo.ng(taskType);
//                                }
//                                try {
//                                    Thread.sleep(1000);
//                                } catch (InterruptedException e) {
//                                    throw new RuntimeException(e);
//                                }
//                            }
//                            boolean b = inboundLineBody.writeWithRetry(inbFeedback, MaterialStatus.AGV_TRANSPORT_COMPLETE.getStatus(), unitId, MaterialStatus.RETRY_COUNT.getStatus());
//                            if (!b){
//                                return AgvTaskSubmitVo.ng(taskType);
//                            }
//                            boolean b2 = wcsLineBodyInboundService.updateTaskIssueTime(id);
//                            //下发预调度
//                            TaskPretaskDto taskPretaskDto = new TaskPretaskDto();
//                            taskPretaskDto.setSiteCode(TaskType.THREE_SITE_RU.getMessage());
//                            WcsConfiguration wcsConfiguration = wcsConfigurationService.selectKey(TaskType.TWO_FLOOR_PRE_SCHEDULING_TIME.getMessage());
//                            String configValue = wcsConfiguration.getConfigValue();
//                            taskPretaskDto.setNextTaskTime(configValue);
//                            taskPretaskDto.setRobotType(String.valueOf(TaskType.THREE_FLOOR_ROBOT_TYPE.getStatus()));
//                            AgvTaskSubmitVo agvTaskSubmitVo = agvSendService.taskPretask(taskPretaskDto);
//
//                        } else if (wcsLineEdgeWarehouse != null) {
//                            //储位修改为空
//                            boolean b3 = wcsLineEdgeWarehouseService.updateStatusIsAgv(source, null, TaskStatus.LINE_EDGE_WAREHOUSE_IDLE.getStatus(), 0);
//                        }
//                    }
                    else if (containerType == 5) {
                        //3楼空栈板入库
                        WcsLineBodyInbound wcsLineBody = wcsLineBodyService.selectHoistStorage(destination);
                        if (wcsLineBody != null) {
                            //将起点储位释放
//                            boolean b1 = iwsSOutsideService.updateStatus(source, null, 0);
                            boolean b1 = wcsLineEdgeWarehouseService.updateStatusIsAgv(source, null, 0, 0);
                            if (!b1) {
                                haikang.error("3楼空托盘入库失败，数据库异常");
                                throw new RuntimeException("3楼空托盘入库失败，数据库异常");
                            }
                        }
                    }
                }
                if (isWms == 1) {
                    //通知WMS取货完成
                    takeReportDto takeReportDto = new takeReportDto();
                    takeReportDto.setContainerCode(containerCode);
                    takeReportDto.setStorageCode(source);
                    takeReportDto.setType(TaskType.OUTBOUND_TAKE_BOX.getStatus());
                    takeReportDto.setTaskType(taskType);
                    if (source.equals(TaskType.ONE_FLOOR_ALTIMETRY.getMessage())) {
                        takeReportDto.setBoundType(3);
                    } else {
                        takeReportDto.setBoundType(1);
                    }
                    takeReportDto.setWmsTaskId(wmsTaskId);
                    takeReportDto.setFloor(floor);
                    if (isNest == 1) {
                        takeReportDto.setNest(true);
                    } else {
                        takeReportDto.setNest(false);
                    }
                    wcsReportService.pickPlaceReport(takeReportDto);
                }
                //入库任务，agv取货完成
                boolean b = wcsInboundMissionService.updateMissionStatusAndAgvId(id, TaskStatus.task_take.getStatus(), agvId);
                if (!b) {
                    haikang.error("agv上报取货，修改数据库失败，数据库异常");
                    throw new RuntimeException("agv上报取货，修改数据库失败，数据库异常");
                }
                return AgvTaskSubmitVo.OK(robotTaskCode);
            } else if ("end".equals(method)) {
                if (missionStatus == 1) {
                    return AgvTaskSubmitVo.ng(robotTaskCode);
                }
                if (isPlc == 1) {
//                    if (containerType == 5) {
//                        //3楼空栈板入库
//                        WcsLineBodyInbound wcsLineBody = wcsLineBodyService.selectHoistStorage(destination);
//                        if (wcsLineBody != null) {
//                            Integer hoiStTransportReply = wcsLineBody.getHoiStTransportReply();
//                            Integer unitId = wcsLineBody.getUnitId();
//                            boolean b = inboundLineBody.writeWithRetry(hoiStTransportReply, 3, unitId, MaterialStatus.RETRY_COUNT.getStatus());
//                            if (!b){
//                                return AgvTaskSubmitVo.ng(taskType);
//                            }
//                        }
//                    } else
//                        if (containerType == 3) {
//                        //根据终点判断是否是三楼入库线体储位
//                        WcsLineBodyInbound wcsLineBodyInbound = wcsLineBodyInboundService.selectChainMachineStorage(destination);
//                        if (wcsLineBodyInbound != null) {
//                            Integer unitId = wcsLineBodyInbound.getUnitId();
//                            //通知plc放货完成
//                            Integer inbOneChainMachineResult = wcsLineBodyInbound.getInbOneChainMachineResult();
//                            boolean b = inboundLineBody.writeWithRetry(inbOneChainMachineResult, 2, unitId, MaterialStatus.RETRY_COUNT.getStatus());
//                            if (!b){
//                                return AgvTaskSubmitVo.ng(taskType);
//                            }
//                        }
//                    }
                }
                if (isWms == 1) {
                    //上报WMS栈板入库
                    takeReportDto takeReportDto = new takeReportDto();
                    takeReportDto.setContainerCode(containerCode);
                    takeReportDto.setStorageCode(destination);
                    takeReportDto.setType(TaskType.OUTBOUND_PUT_BOX.getStatus());
                    takeReportDto.setTaskType(taskType);
                    if (destination.equals(TaskType.ONE_FLOOR_ALTIMETRY.getMessage())) {
                        takeReportDto.setBoundType(3);
                    } else {
                        takeReportDto.setBoundType(1);
                    }
                    takeReportDto.setWmsTaskId(wmsTaskId);
                    takeReportDto.setFloor(floor);
                    if (isNest == 1) {
                        takeReportDto.setNest(true);
                    } else {
                        takeReportDto.setNest(false);
                    }
                    boolean b2 = wcsReportService.pickPlaceReport(takeReportDto);
                }

                //删除入库任务
//                boolean b1 = wcsInboundMissionService.deleteInboundId(wcsInboundMission.getId());
                boolean b1 = wcsInboundMissionService.updateMissionStatus(inboundCode, TaskStatus.Task_complete.getStatus());
                return AgvTaskSubmitVo.OK(robotTaskCode);
            } else if ("middle".equals(method)) {
                //中间点上报，占用储位
                iwsSOutsideService.updateStatus(TaskType.ONE_FLOOR_RETURN_TO_STORAGE_LOCATION.getMessage(), containerCode, 3);
                return AgvTaskSubmitVo.OK(robotTaskCode);
            } else if ("取消".equals(method)) {
                //入库取消
                boolean b1 = wcsInboundMissionService.updateMissionStatus(inboundCode, TaskStatus.Task_cancel.getStatus());
                //通知wms入库取消
                CancelInboundStorageDto cancelInboundStorageDto = new CancelInboundStorageDto();
                cancelInboundStorageDto.setStorageId(wcsInboundMission.getDestination());
                cancelInboundStorageDto.setContainerCode(wcsInboundMission.getContainerCode());
                if (isNest == 1) {
                    cancelInboundStorageDto.setNest(true);
                } else {
                    cancelInboundStorageDto.setNest(false);
                }
                boolean b = wcsReportService.cancelInboundStorage(cancelInboundStorageDto);
                if (!b) {
                    haikang.warn("入库取消WMS返回错误");
                }
                return AgvTaskSubmitVo.OK(robotTaskCode);
            }
        } else if (wcsOutboundMission != null) {
            //出库上报
            Extra extra = agvReturnDto.getExtra();
            Values values = extra.getValues();
            String method = values.getMethod();
            Integer id = wcsOutboundMission.getId();
            String outboundContainerCode = wcsOutboundMission.getContainerCode();
            String source = wcsOutboundMission.getSource();
            String destination = wcsOutboundMission.getDestination();
            String taskType = wcsOutboundMission.getTaskType();
            Integer containerType = wcsOutboundMission.getContainerType();
            Integer isNest = wcsOutboundMission.getIsNest();
            String wmsTaskId = wcsOutboundMission.getWmsTaskId();
            String outboundCode = wcsOutboundMission.getOutboundCode();
            String containerCode = wcsOutboundMission.getContainerCode();
            String floor = wcsOutboundMission.getFloor();
            Integer isWms = wcsOutboundMission.getIsWms();
            Integer missionStatus = wcsOutboundMission.getMissionStatus();
            if ("start".equals(method)) {
                return AgvTaskSubmitVo.OK(robotTaskCode);
            } else if ("outbin".equals(method)) {
                if (missionStatus == 4) {
                    return AgvTaskSubmitVo.ng(robotTaskCode);
                }
                //向3楼plc发送取走空栈板
//                if (containerType == 5) {
//                    //3楼空栈板入库
//                    WcsLineBodyInbound wcsLineBody = wcsLineBodyService.selectHoistStorage(source);
//                    if (wcsLineBody != null) {
//                        Integer hoiStTransportReply = wcsLineBody.getHoiStTransportReply();
//                        Integer unitId = wcsLineBody.getUnitId();
//                        boolean b = inboundLineBody.writeWithRetry(hoiStTransportReply, 2, unitId, MaterialStatus.RETRY_COUNT.getStatus());
//                        if (!b){
//                            haikang.info("3楼plc发送取走空栈板失败");
//                            return AgvTaskSubmitVo.ng(robotTaskCode);
//                        }
//                    }
//                }
                //入库任务，agv取货完成
                boolean b = wcsOutboundMissionService.updateMissionStatusAndAgvId(id, TaskStatus.task_take.getStatus(), agvId);
                if (!b) {
                    haikang.error("agv出库上报取货，修改数据库失败，数据库异常");
                    throw new RuntimeException("agv出库上报取货，修改数据库失败，数据库异常");
                }
                if (isWms == 1) {
                    //发送WMS出库取货
                    takeReportDto takeReportDto = new takeReportDto();
                    takeReportDto.setContainerCode(outboundContainerCode);
                    takeReportDto.setStorageCode(source);
                    takeReportDto.setType(TaskType.OUTBOUND_TAKE_BOX.getStatus());
                    takeReportDto.setTaskType(taskType);
                    takeReportDto.setBoundType(2);
                    takeReportDto.setWmsTaskId(wmsTaskId);
                    takeReportDto.setFloor(floor);
                    if (isNest == 1) {
                        takeReportDto.setNest(true);
                    } else {
                        takeReportDto.setNest(false);
                    }
                    boolean b2 = wcsReportService.pickPlaceReport(takeReportDto);
                    if (!b2) {
                        haikang.error("出库放货修改数据库失败");
                        throw new RuntimeException("出库放货修改数据库失败");
                    }
                }
                return AgvTaskSubmitVo.OK(robotTaskCode);
            } else if ("end".equals(method)) {
                if (missionStatus == 1) {
                    return AgvTaskSubmitVo.ng(robotTaskCode);
                }
                //终点为3楼CTU放货位置，需要通知PLC放货完成
//                if (containerType == 3) {
//                    WcsLineBodyOutbound wcsLineBodyOutbound = wcsLineBodyOutboundService.selectOne();
//                    if (wcsLineBodyOutbound != null) {
//                        String ctuPutStorage = wcsLineBodyOutbound.getCtuPutStorage();
//                        Integer oneTeturnResult = wcsLineBodyOutbound.getOneTeturnResult();
//                        Integer unitId = wcsLineBodyOutbound.getUnitId();
//                        if (ctuPutStorage.equals(destination)) {
//                            Integer readHoldingRegisters = outboundLineBody.readHoldingRegisters(oneTeturnResult, unitId);
//                            if (readHoldingRegisters == 0) {
//                                haikang.info("PLC手动，信息归0，重发1");
//                                boolean b = outboundLineBody.writeWithRetry(oneTeturnResult, 1, unitId, MaterialStatus.RETRY_COUNT.getStatus());
//                                if (!b){
//                                    return AgvTaskSubmitVo.ng(robotTaskCode);
//                                }
//                            }
//                            //通知PLC第一段放货完成
//                            boolean b = outboundLineBody.writeWithRetry(oneTeturnResult, 2, unitId, MaterialStatus.RETRY_COUNT.getStatus());
//                            haikang.info("3楼出库PLC放货完成，通知PLC放货完成，地址位：{}，任务id：{}，时间：{}", oneTeturnResult, robotTaskCode, LocalDateTime.now());
//                            if (!b) {
//                                haikang.error("通知3楼plc，CTU放货完成，通知失败");
//                                throw new RuntimeException("通知3楼plc，CTU放货完成，通知失败");
//                            }
//                            //更具容器编码查询当前工单容器是否都完成出库
//                            WcsThreeFloorOutboundDetails wcsThreeFloorOutboundDetails = wcsThreeFloorOutboundDetailsService.selectContainer(containerCode);
//                            if (wcsThreeFloorOutboundDetails != null) {
//                                Integer id1 = wcsThreeFloorOutboundDetails.getId();
//                                //修改AGV放货完成
//                                boolean b3 = wcsThreeFloorOutboundDetailsService.updateAgvReleaseCompleted(id1, 1);
//                                String workOrder = wcsThreeFloorOutboundDetails.getWorkOrder();
//                                List<WcsThreeFloorOutboundDetails> wcsThreeFloorOutboundDetailsList = wcsThreeFloorOutboundDetailsService.selectWorkOrder(workOrder);
//                                //根据工单号查询AGV搬运完成数量
//                                Integer agvContainerSize = wcsThreeFloorOutboundDetailsService.selectAgvContainerSize(workOrder, 1);
//                                int size = wcsThreeFloorOutboundDetailsList.size();
//                                WcsThreeFloorOutbound wcsThreeFloorOutbound = wcsThreeFloorOutboundService.selectWorkOrder(workOrder);
//                                Integer total = wcsThreeFloorOutbound.getTotal();
//                                haikang.info("3楼出库任务数量：{},完成数量：{},工单总数：{}", size, agvContainerSize, total);
//                                if (size == agvContainerSize && size == total) {
//                                    //出库完成，通知wms当前出库单出库完成
//                                    wcsThreeFloorOutboundService.updateWmsStatus(workOrder, 1);
//                                    boolean b2 = wcsReportService.wmsThreeFloorWorkOrderComplete(workOrder);
//                                }
//                            }
//                        }
//                    }
//                } else
                    if (containerType == 2) {
                    //2楼取走告知PLC
                    String fluentFrameStorage = wcsOutboundMission.getFluentFrameStorage();
                    WcsFluentFrameConfig wcsFluentFrameConfig = wcsFluentFrameConfigService.selectOutStorageCode(fluentFrameStorage);
                    if (wcsFluentFrameConfig != null) {
                        Integer threeOutReturnResult = wcsFluentFrameConfig.getThreeOutReturnResult();
                        Integer unitId = wcsFluentFrameConfig.getUnitId();
                        String region = wcsFluentFrameConfig.getRegion();
                        boolean b = fluentFrame.writeWithRetry(threeOutReturnResult, MaterialStatus.AGV_TRANSPORT_COMPLETE.getStatus(), unitId, MaterialStatus.RETRY_COUNT.getStatus(), region);
                        if (!b){
                            haikang.info("2楼取走告知PLC失败");
                            //写入失败，记录
                            WcsRetryPlc wcsRetryPlc = new WcsRetryPlc();
                            wcsRetryPlc.setFloor(floor);
                            wcsRetryPlc.setType(2);
                            wcsRetryPlc.setAddress(threeOutReturnResult);
                            wcsRetryPlc.setRegion(region);
                            wcsRetryPlc.setValue(MaterialStatus.AGV_TRANSPORT_COMPLETE.getStatus());
                            haikang.info("2F入库PLC写入失败,记录：{}",wcsRetryPlc);
                            wcsRetryPlcService.insert(wcsRetryPlc);
//                            return AgvTaskSubmitVo.ng(robotTaskCode);
                        }
                    }
                }
                if (Objects.equals(TaskType.EMPTY_MATERIAL_BOX.getStatus(), containerType)) {
                    //空箱出库，需要扣减数量
                    WcsFluentFrameConfig wcsFluentFrameConfig = wcsFluentFrameConfigService.selectStorageCode(destination);
                    if (wcsFluentFrameConfig != null) {
                        Integer fluentFrameConfigId = wcsFluentFrameConfig.getId();
                        Integer size = wcsFluentFrameConfig.getSize();
                        size--;
                        //扣减数量
                        wcsFluentFrameConfigService.updateSize(fluentFrameConfigId, size);
                    }
                }
                //3楼取走空栈板放货完成，占用储位
                if (containerType == 5) {
                    //3楼空栈板入库
//                    boolean b = iwsSOutsideService.updateStatus(destination, containerCode, 3);
                    boolean b = wcsLineEdgeWarehouseService.updateStatusIsAgv(destination, containerCode, 3, 1);
                    if (!b) {
                        haikang.error("3楼空栈板出库,数据库异常");
                        throw new RuntimeException("3楼空栈板出库,数据库异常");
                    }
                    boolean b2 = wcsLineEdgeWarehouseService.updateEmptyTrayQuantityStatus(destination, 12, TaskStatus.LINE_EDGE_WAREHOUSE_EMPTY_PALLET.getStatus());
                }
                if (isWms == 1) {
                    takeReportDto takeReportDto = new takeReportDto();
                    takeReportDto.setContainerCode(outboundContainerCode);
                    if (containerType == 4){
                        WcsFluentFrameConfig wcsFluentFrameConfig = wcsFluentFrameConfigService.selectOutStorageCode(destination);
                        if (wcsFluentFrameConfig != null) {
                            takeReportDto.setStorageCode(wcsFluentFrameConfig.getDeviceIp());
                        }
                    }else {
                        takeReportDto.setStorageCode(destination);
                    }
                    takeReportDto.setType(TaskType.OUTBOUND_PUT_BOX.getStatus());
                    takeReportDto.setTaskType(taskType);
                    takeReportDto.setBoundType(2);
                    takeReportDto.setWmsTaskId(wmsTaskId);
                    takeReportDto.setFloor(floor);
                    if (isNest == 1) {
                        takeReportDto.setNest(true);
                    } else {
                        takeReportDto.setNest(false);
                    }
                    boolean b2 = wcsReportService.pickPlaceReport(takeReportDto);
                    if (!b2) {
                        haikang.error("出库放货修改数据库失败");
                        throw new RuntimeException("出库放货修改数据库失败");
                    }
                }
                //修改出库任务
                boolean b1 = wcsOutboundMissionService.updateMissionStatus(outboundCode, TaskStatus.Task_complete.getStatus());
                if (!b1) {
                    haikang.error("出库放货完成，移到历史表失败");
                    throw new RuntimeException("出库放货完成，移到历史表失败");
                }
                return AgvTaskSubmitVo.OK(robotTaskCode);
            }
//            else if ("middle".equals(method)){
//                //记录3楼agv到达plc出库口
//                if (containerType.equals(TaskType.THREE_WORKBIN.getStatus())){
//                    WcsLineBodyWaitOutbound wcsLineBodyWaitOutbound = new WcsLineBodyWaitOutbound();
//                    wcsLineBodyWaitOutbound.setTaskCode(outboundCode);
//                    boolean b = wcsLineBodyWaitOutboundService.insertWaitOutbound(wcsLineBodyWaitOutbound);
//                    if (!b){
//                        haikang.error("3楼出库到入库口记录数据失败,数据库异常");
//                        throw new RuntimeException("3楼出库到入库口记录数据失败,数据库异常");
//                    }
//                    return AgvTaskSubmitVo.OK(robotTaskCode);
//                }else if (containerType.equals(TaskType.WORKBIN.getStatus())){
//                    //2楼料箱出库，修改状态
//                    WcsFluentFrameOutboundDetails wcsFluentFrameOutboundDetails = wcsFluentFrameOutboundDetailsService.selectContainerCode(containerCode);
//                    if (wcsFluentFrameOutboundDetails !=null){
//                        //修改agv到达中间点放货完成
//                        boolean b = wcsFluentFrameOutboundDetailsService.updateAgvPlace(wcsFluentFrameOutboundDetails.getId(),1);
//                        return AgvTaskSubmitVo.OK(robotTaskCode);
//                    }
//                }
//            }
        } else if (wcsDeliveryMission != null) {
            Integer id = wcsDeliveryMission.getId();
            String containerCode = wcsDeliveryMission.getContainerCode();
            String destination = wcsDeliveryMission.getDestination();
            String source = wcsDeliveryMission.getSource();
            String deliveryCode = wcsDeliveryMission.getDeliveryCode();
            Integer lineEdgeWarehouse = wcsDeliveryMission.getReportWms();
            String floor = wcsDeliveryMission.getFloor();
            Integer containerType = wcsDeliveryMission.getContainerType();
            Integer missionStatus = wcsDeliveryMission.getMissionStatus();
            Extra extra = agvReturnDto.getExtra();
            Values values = extra.getValues();
            String method = values.getMethod();
            if ("start".equals(method)) {
                return AgvTaskSubmitVo.OK(robotTaskCode);
            } else if ("outbin".equals(method)) {
                if (missionStatus == 4) {
                    return AgvTaskSubmitVo.ng(robotTaskCode);
                }
//                if (containerType == 4) {
//                    //通知plc取货完成
//                    WcsLineBodyOutbound wcsLineBodyOutbound = wcsLineBodyOutboundService.selectOne();
//                    if (wcsLineBodyOutbound != null) {
//                        String oneStorageCode = wcsLineBodyOutbound.getOneStorageCode();
//                        String twoStorageCode = wcsLineBodyOutbound.getTwoStorageCode();
//                        Integer oneChainTransportResult = wcsLineBodyOutbound.getOneChainTransportResult();
//                        Integer twoChainTransportResult = wcsLineBodyOutbound.getTwoChainTransportResult();
//                        Integer unitId = wcsLineBodyOutbound.getUnitId();
//                        if (oneStorageCode.equals(source)) {
//                            //通知第一段取货完成
//                            boolean b2 = outboundLineBody.writeWithRetry(oneChainTransportResult, 2, unitId, MaterialStatus.RETRY_COUNT.getStatus());
//                            if (!b2) {
//                                haikang.error("通知3楼plc连条线取货通知失败");
//                                throw new RuntimeException("通知3楼plc连条线取货通知失败");
//                            }
//                        } else if (twoStorageCode.equals(source)) {
//                            //通知第二段取货完成
//                            boolean b2 = outboundLineBody.writeWithRetry(twoChainTransportResult, 2, unitId, MaterialStatus.RETRY_COUNT.getStatus());
//                            if (!b2) {
//                                haikang.error("通知3楼plc连条线取货通知失败");
//                                throw new RuntimeException("通知3楼plc连条线取货通知失败");
//                            }
//                        }
//                        WcsDeliveryMission wcsDeliveryMission1 = wcsDeliveryMissionService.selectDeliveryCode(deliveryCode);
//                        if (wcsDeliveryMission1 != null) {
//                            String containerCode1 = wcsDeliveryMission1.getContainerCode();
//                            List<WcsThreeFloorOutboundDetails> wcsThreeFloorOutboundDetails = wcsThreeFloorOutboundDetailsService.selectPalletCode(containerCode1);
//                            if (wcsThreeFloorOutboundDetails != null) {
//                                List<String> containerList = wcsThreeFloorOutboundDetails.stream().map(WcsThreeFloorOutboundDetails::getContainerCode).collect(Collectors.toList());
//                                ThreeFloorDeliveryProductionLineDto threeFloorDeliveryProductionLineDto = new ThreeFloorDeliveryProductionLineDto();
//                                WcsThreeFloorOutboundDetails wcsThreeFloorOutboundDetails1 = wcsThreeFloorOutboundDetails.get(0);
//                                threeFloorDeliveryProductionLineDto.setWorkOrder(wcsThreeFloorOutboundDetails1.getWorkOrder());
//                                threeFloorDeliveryProductionLineDto.setStorageCode(destination);
//                                threeFloorDeliveryProductionLineDto.setContainerCodeList(containerList);
//                                threeFloorDeliveryProductionLineDto.setSource("R3FchuA01011");
//                                threeFloorDeliveryProductionLineDto.setType(1);
//                                haikang.info("M3配送到线边仓上报wms:{}", threeFloorDeliveryProductionLineDto);
//                                boolean b2 = wcsReportService.wmsThreeFloorDeliveryProductionLine(threeFloorDeliveryProductionLineDto);
//                                if (!b2) {
//                                    haikang.error("配送到线边WMS报错");
//                                    throw new RuntimeException("配送到线边WMS报错");
//                                }
//                            }
//                        }
//                    }
//                }
                //通知wmsAGV取货
                if (lineEdgeWarehouse == 1) {
                    takeReportDto takeReportDto = new takeReportDto();
                    takeReportDto.setContainerCode(containerCode);
                    takeReportDto.setStorageCode(source);
                    takeReportDto.setType(TaskType.OUTBOUND_TAKE_BOX.getStatus());
//                takeReportDto.setTaskType(taskType);
                    takeReportDto.setBoundType(2);
//                takeReportDto.setWmsTaskId(wmsTaskId);
                    takeReportDto.setNest(false);
                    takeReportDto.setFloor(floor);
                    boolean b2 = wcsReportService.pickPlaceReport(takeReportDto);
                    if (!b2) {
                        haikang.error("出库放货修改数据库失败");
                        throw new RuntimeException("出库放货修改数据库失败");
                    }
                }
                //配送任务，agv取货完成
                boolean b = wcsDeliveryMissionService.updateDeliveryStatusAndAgvId(id, TaskStatus.task_take.getStatus(), agvId);
                if (!b) {
                    haikang.error("agv配送任务上报取货，修改数据库失败，数据库异常");
                    throw new RuntimeException("agv配送任务上报取货，修改数据库失败，数据库异常");
                }
                return AgvTaskSubmitVo.OK(robotTaskCode);
            } else if ("end".equals(method)) {
                //状态为1上报放货报错
                if (missionStatus == 1) {
                    return AgvTaskSubmitVo.ng(robotTaskCode);
                }
                //判断是否为线边仓储位
                WcsLineEdgeWarehouse wcsLineEdgeWarehouse = wcsLineEdgeWarehouseService.selectStorageCode(destination);
                if (wcsLineEdgeWarehouse != null) {
                    boolean b = wcsLineEdgeWarehouseService.updateStatusIsAgv(destination, containerCode, TaskStatus.LINE_EDGE_WAREHOUSE_OCCUPIED.getStatus(), 1);
                    if (!b) {
                        haikang.error("agv放货，修改配送任务到线边仓修改数据库失败");
                        throw new RuntimeException("agv放货，修改配送任务到线边仓修改数据库失败");
                    }
                }
                if (lineEdgeWarehouse == 1) {
                    //agv放货将线边仓占用，通知WMS
//                    wcsLineEdgeWarehouseService.select
                    //配送任务放货，上报wms
                    takeReportDto takeReportDto = new takeReportDto();
                    takeReportDto.setContainerCode(containerCode);
                    takeReportDto.setStorageCode(destination);
                    takeReportDto.setType(TaskType.OUTBOUND_PUT_BOX.getStatus());
//                    takeReportDto.setTaskType(taskType);
                    takeReportDto.setBoundType(2);
//                    takeReportDto.setWmsTaskId(wmsTaskId);`
                    takeReportDto.setNest(false);
                    takeReportDto.setFloor(floor);
                    boolean b2 = wcsReportService.pickPlaceReport(takeReportDto);
                    if (!b2) {
                        haikang.error("出库放货修改数据库失败");
                        throw new RuntimeException("出库放货修改数据库失败");
                    }
                } else {
                    iwsSOutsideService.updateStatus(destination, containerCode, 3);
                }
                if (containerType == 4) {
                    //向wms上报3楼出库料箱到达储位
                    List<WcsThreeFloorOutboundDetails> wcsThreeFloorOutboundDetailsList = wcsThreeFloorOutboundDetailsService.selectPalletCode(containerCode);
                    if (!wcsThreeFloorOutboundDetailsList.isEmpty()) {
                        List<String> containerList = wcsThreeFloorOutboundDetailsList.stream().map(WcsThreeFloorOutboundDetails::getContainerCode).collect(Collectors.toList());
                        String workOrder1 = wcsThreeFloorOutboundDetailsList.get(0).getWorkOrder();
                        //上报wms
                        ThreeFloorDeliveryProductionLineDto threeFloorDeliveryProductionLineDto = new ThreeFloorDeliveryProductionLineDto();
                        threeFloorDeliveryProductionLineDto.setWorkOrder(workOrder1);
                        threeFloorDeliveryProductionLineDto.setStorageCode(destination);
                        threeFloorDeliveryProductionLineDto.setContainerCodeList(containerList);
                        threeFloorDeliveryProductionLineDto.setSource("R3FchuA01011");
                        threeFloorDeliveryProductionLineDto.setType(2);
                        haikang.info("M3配送到线边仓上报wms:{}", threeFloorDeliveryProductionLineDto);
                        boolean b2 = wcsReportService.wmsThreeFloorDeliveryProductionLine(threeFloorDeliveryProductionLineDto);
                        if (!b2) {
                            haikang.error("配送到线边WMS报错");
                            throw new RuntimeException("配送到线边WMS报错");
                        }
                        //将栈板移到历史表
                        for (WcsThreeFloorOutboundDetails wcsThreeFloorOutboundDetails : wcsThreeFloorOutboundDetailsList) {
                            Integer id1 = wcsThreeFloorOutboundDetails.getId();
                            WcsThreeFloorOutboundDetailsHistory wcsThreeFloorOutboundDetailsHistory = new WcsThreeFloorOutboundDetailsHistory();
                            BeanUtils.copyProperties(wcsThreeFloorOutboundDetails, wcsThreeFloorOutboundDetailsHistory);
                            wcsThreeFloorOutboundDetailsHistory.setId(null);
                            boolean b = wcsThreeFloorOutboundDetailsHistoryService.insert(wcsThreeFloorOutboundDetailsHistory);
                            //删除3楼出库单明细
                            boolean b1 = wcsThreeFloorOutboundDetailsService.deleteId(id1);
                        }
                        //查询明细表工单号是否为0
                        WcsThreeFloorOutboundDetails wcsThreeFloorOutboundDetails = wcsThreeFloorOutboundDetailsList.get(0);
                        String workOrder = wcsThreeFloorOutboundDetails.getWorkOrder();
                        List<WcsThreeFloorOutboundDetails> wcsThreeFloorOutboundDetailsS = wcsThreeFloorOutboundDetailsService.selectWorkOrder(workOrder);
                        if (wcsThreeFloorOutboundDetailsS.isEmpty()) {
                            //出库单移到历史表
                            WcsThreeFloorOutbound wcsThreeFloorOutbound = wcsThreeFloorOutboundService.selectWorkOrder(workOrder);
                            if (wcsThreeFloorOutbound != null) {
                                int id1 = wcsThreeFloorOutbound.getId();
                                WcsThreeFloorOutboundHistory wcsThreeFloorOutboundHistory = new WcsThreeFloorOutboundHistory();
                                BeanUtils.copyProperties(wcsThreeFloorOutbound, wcsThreeFloorOutboundHistory);
                                wcsThreeFloorOutboundHistory.setId(null);
                                boolean b = wcsThreeFloorOutboundHistoryService.insert(wcsThreeFloorOutboundHistory);
                                //删除出库单
                                boolean b1 = wcsThreeFloorOutboundService.deleteId(id1);
                            }
                        }
                    }
                }
                //修改配送库任务
                boolean b1 = wcsDeliveryMissionService.updateMissionStatus(deliveryCode, TaskStatus.Task_complete.getStatus());
                return AgvTaskSubmitVo.OK(robotTaskCode);
            }
        } else if (wcsInboundAbnormalMission != null) {
            Integer id = wcsInboundAbnormalMission.getId();
            String containerCode = wcsInboundAbnormalMission.getContainerCode();
            String destination = wcsInboundAbnormalMission.getDestination();
            String abnormalCode = wcsInboundAbnormalMission.getAbnormalCode();
            Integer containerType = wcsInboundAbnormalMission.getContainerType();
            String source = wcsInboundAbnormalMission.getSource();
            Integer missionStatus = wcsInboundAbnormalMission.getMissionStatus();
            Extra extra = agvReturnDto.getExtra();
            Values values = extra.getValues();
            String method = values.getMethod();
            if ("start".equals(method)) {
                return AgvTaskSubmitVo.OK(robotTaskCode);
            } else if ("outbin".equals(method)) {
                if (missionStatus == 4) {
                    return AgvTaskSubmitVo.ng(robotTaskCode);
                }
                if (containerType == 1) {
                    //1楼链条机
                    WcsChainLineConfig wcsChainLineConfig = wcsChainLineConfigService.selectTransportStorage(source);
                    if (wcsChainLineConfig != null) {
                        Integer threeReturnResult = wcsChainLineConfig.getThreeReturnResult();
                        Integer unitId = wcsChainLineConfig.getUnitId();
                        chainLineTCP.writeWithRetry(threeReturnResult, MaterialStatus.AGV_TRANSPORT_COMPLETE.getStatus(), unitId, MaterialStatus.RETRY_COUNT.getStatus());
                        //通知AGV成功，修改任务状态
                    }
                }
//                else if (containerType == 3) {
//                    //3楼机械臂ng
//                    WcsLineBodyInbound wcsLineBody = wcsLineBodyService.selectNgStorage(source);
//                    if (wcsLineBody != null) {
//                        Integer ngTransport = wcsLineBody.getNgTransport();
//                        Integer unitId = wcsLineBody.getUnitId();
//                        inboundLineBody.writeWithRetry(ngTransport, MaterialStatus.AGV_TRANSPORT_COMPLETE.getStatus(), unitId, MaterialStatus.RETRY_COUNT.getStatus());
//                    }
//                }
                //配送任务，agv取货完成
                String carrierName = values.getCarrierName();
                boolean b = wcsInboundAbnormalMissionService.updateAbnormalStatusAndAgvId(id, TaskStatus.task_take.getStatus(), carrierName);
                if (!b) {
                    haikang.error("agv配送任务上报取货，修改数据库失败，数据库异常");
                    throw new RuntimeException("agv配送任务上报取货，修改数据库失败，数据库异常");
                }
                return AgvTaskSubmitVo.OK(robotTaskCode);
            } else if ("end".equals(method)) {
                if (missionStatus == 1) {
                    return AgvTaskSubmitVo.ng(robotTaskCode);
                }
//                IwsSOutside iwsSOutside = iwsSOutsideService.selectStorageCode(destination);
                WcsLineEdgeWarehouse wcsLineEdgeWarehouse = wcsLineEdgeWarehouseService.selectStorageCode(destination);
                if (wcsLineEdgeWarehouse != null) {
                    //占用储位
                    wcsLineEdgeWarehouseService.updateStatusIsAgv(destination, containerCode, TaskStatus.LINE_EDGE_WAREHOUSE_OCCUPIED.getStatus(), 1);
                    //判断入库任务储位是否是库外储位，是将储位释放
//                    iwsSOutsideService.updateStatus(destination,containerCode,3);
//                    if (containerType == 1){
//                        List<IwsSOutside> iwsSOutsideList= iwsSOutsideService.selectStoreName(TaskType.STORAGE_TYPE_ONE_FLOOR_NEW_ABNORMAL.getMessage());
//                        if (!iwsSOutsideList.isEmpty()){
//                            McuDto mcuDto = new McuDto();
//                            ArrayList<McuCount> mcuCounts = new ArrayList<>();
//                            McuCount mcuCount = new McuCount();
//                            mcuCount.setCount(iwsSOutsideList.size());
//                            mcuCounts.add(mcuCount);
//                            mcuDto.setDetails(mcuCounts);
//                            buzzerService.mcuSend(mcuDto,"127.0.0.1");
//                        }
//                    }else if (containerType == 3){
//                        //占用储位
//                        wcsLineEdgeWarehouseService.updateStatusIsAgv(destination,containerCode, TaskStatus.LINE_EDGE_WAREHOUSE_OCCUPIED.getStatus(), 1);
//                        List<WcsLineEdgeWarehouse> wcsLineEdgeWarehouses = wcsLineEdgeWarehouseService.selectRegionAvailableSize(TaskType.STORAGE_TYPE_THREE_FLOOR_NEW_ABNORMAL.getMessage());
////                        List<IwsSOutside> iwsSOutsideList= iwsSOutsideService.selectStoreName(TaskType.STORAGE_TYPE_THREE_FLOOR_NEW_ABNORMAL.getMessage());
//                        if (!wcsLineEdgeWarehouses.isEmpty()){
//                            McuDto mcuDto = new McuDto();
//                            ArrayList<McuCount> mcuCounts = new ArrayList<>();
//                            McuCount mcuCount = new McuCount();
//                            mcuCount.setCount(wcsLineEdgeWarehouses.size());
//                            mcuCounts.add(mcuCount);
//                            mcuDto.setDetails(mcuCounts);
//                            buzzerService.mcuSend(mcuDto,"127.0.0.1");
//                        }
//                    }
                }
                //修改入库异常任务
                boolean b1 = wcsInboundAbnormalMissionService.updateMissionStatus(abnormalCode, TaskStatus.Task_complete.getStatus());
                if (!b1) {
                    haikang.error("AGV放货完成，修改数据库状态失败");
                    throw new RuntimeException("AGV放货完成，修改数据库状态失败");
                }
                return AgvTaskSubmitVo.OK(robotTaskCode);
            }
        }
        return AgvTaskSubmitVo.ng(robotTaskCode);
    }

    @Transactional
    @Override
    public AgvTaskSubmitVo agvRequestLift(AgvRequestLiftDto agvRequestLiftDto) {
        haikang.info("请求电梯请求参数：{}", agvRequestLiftDto);
        //设备编号
        String eqptCode = agvRequestLiftDto.getEqptCode();
        //设备名称
//        String eqptName = agvRequestLiftDto.getEqptName();
        //任务号为唯一编号，可使用 UUID
        String taskCode = agvRequestLiftDto.getTaskCode();
        //任务执行方法，与设备相关，可扩展枚举值。
        String method = agvRequestLiftDto.getMethod();
        //起点
        String srcCode = agvRequestLiftDto.getSrcCode();
        //终点
        String dstCode = agvRequestLiftDto.getDstCode();
        if (LiftTaskStatus.APPLY_FROM_AGV.getMessage().equals(method)) {
            WcsAgvReleaseGoods wcsAgvReleaseGoods = wcsAgvReleaseGoodsService.selectTaskCode(taskCode);
            if (wcsAgvReleaseGoods != null) {
                WcsOutboundMission wcsOutboundMission = wcsOutboundMissionService.selectOutboundCode(taskCode);
                WcsInboundMission wcsInboundMission = wcsInboundMissionService.selectInboundCode(taskCode);
                if (wcsOutboundMission != null) {
                    Integer containerType = wcsOutboundMission.getContainerType();
                    String floor = wcsOutboundMission.getFloor();
                    boolean b = wcsAgvReleaseGoodsService.updateStatus(wcsAgvReleaseGoods.getId(), TaskStatus.APPLY_RELEASE_GOODS_AGV.getStatus());
                    return AgvTaskSubmitVo.OK(taskCode);
//                    if (containerType == 3 && TaskType.THREE_FLOOR.getMessage().equals(floor)) {
//                        //3楼出库，获取3楼PLC
//                        boolean b = wcsAgvReleaseGoodsService.updateStatus(wcsAgvReleaseGoods.getId(), TaskStatus.APPLY_RELEASE_GOODS_AGV.getStatus());
//                        return AgvTaskSubmitVo.OK(taskCode);
//                    }
                } else if (wcsInboundMission != null) {
                    Integer containerType = wcsInboundMission.getContainerType();
                    String floor = wcsInboundMission.getFloor();
                    if (containerType == 3 && TaskType.THREE_FLOOR.getMessage().equals(floor)) {
                        boolean b = wcsAgvReleaseGoodsService.updateStatus(wcsAgvReleaseGoods.getId(), TaskStatus.APPLY_RELEASE_GOODS_AGV.getStatus());
                        return AgvTaskSubmitVo.OK(taskCode);
                    }
                }
            }
            return AgvTaskSubmitVo.ng(taskCode);
        } else if ("CANCEL".equals(method)) {
            haikang.info("海康外设接口执行通知，请求参数：{}", agvRequestLiftDto);
            return AgvTaskSubmitVo.OK(null);
        } else if (LiftTaskStatus.APPLY_TO_AGV.getMessage().equals(method)) {
            WcsAgvReleaseGoods wcsAgvReleaseGoods = wcsAgvReleaseGoodsService.selectTaskCode(taskCode);
            if (wcsAgvReleaseGoods != null) {
                boolean b = wcsAgvReleaseGoodsService.updateStatus(wcsAgvReleaseGoods.getId(), TaskStatus.APPLY_RELEASE_GOODS_AGV.getStatus());
                return AgvTaskSubmitVo.OK(taskCode);
            }
        }
        return AgvTaskSubmitVo.ng(taskCode);
    }


}
